package cn.mygweb.admin.modules.web.service.impl;

import java.util.List;

import org.assertj.core.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.mygweb.admin.modules.web.mapper.ColumnsMapper;
import cn.mygweb.admin.modules.web.pojo.Columns;
import cn.mygweb.admin.modules.web.pojo.Content;
import cn.mygweb.admin.modules.web.service.ColumnsService;
import cn.mygweb.admin.modules.web.service.ContentService;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/** 
* <p>Title: ColumnsServiceImpl.java</p>
* <p>Description: </p>  
* @author gxb 
* @date 2019年7月1日 
* <p>Copyright: Copyright (c) 2019</p>
* <p>Company: www.mygweb.cn</p> 
*/
@Service
public class ColumnsServiceImpl implements ColumnsService{

	@Autowired
	private ColumnsMapper columnsMapper;
	
	@Autowired
	private ContentService contentService;
	
	/* (non-Javadoc)
	 * <p>Title: queryListByExample</p>
	 * <p>Description: </p>
	 * @param columns
	 * @return
	 * @see cn.mygweb.admin.modules.web.service.ColumnsService#queryListByExample(cn.mygweb.admin.modules.web.pojo.Columns)
	 */
	@Override
	@Transactional(propagation=Propagation.SUPPORTS)
	public List<Columns> queryListByExample(Columns columns) {
		Example example = new Example(Columns.class);
		example.setOrderByClause("sort_num asc");//升序排列
		List<Columns> columnsList = columnsMapper.selectByExample(example);
		for (Columns c : columnsList) {
			Content content = new Content();
			content.setColumnId(c.getId());//链接栏目的id
			List<Content> contentList = contentService.queryListByExample(content); 
			c.setContentList(contentList);
		}
		return columnsList;
	}

	/* (non-Javadoc)
	 * <p>Title: updateByPrimaryKeySelective</p>
	 * <p>Description: </p>
	 * @param columns
	 * @see cn.mygweb.admin.modules.web.service.ColumnsService#updateByPrimaryKeySelective(cn.mygweb.admin.modules.web.pojo.Columns)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void updateByPrimaryKeySelective(Columns columns) {
		columnsMapper.updateByPrimaryKeySelective(columns);
	}

	/* (non-Javadoc)
	 * <p>Title: insert</p>
	 * <p>Description: </p>
	 * @param columns
	 * @see cn.mygweb.admin.modules.web.service.ColumnsService#insert(cn.mygweb.admin.modules.web.pojo.Columns)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void insert(Columns columns) {
		columnsMapper.insert(columns);
	}

	/* (non-Javadoc)
	 * <p>Title: delete</p>
	 * <p>Description: </p>
	 * @param idArr
	 * @see cn.mygweb.admin.modules.web.service.ColumnsService#delete(java.lang.String[])
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void delete(String[] idArr) {
		Example example = new Example(Columns.class);
		Criteria criteria = example.createCriteria();
		List idList = Arrays.asList(idArr);
		criteria.andIn("id", idList);
		columnsMapper.deleteByExample(example);		
	}
	
}
